//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.DataLayer
{
    using System;

    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class ActivityActionCalls : IDataLayerSecurityActionCalls
    {
        private Connection connection;

        /// <summary>
        /// Initializes a new instance of the <see cref="ActivityActionCalls"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public ActivityActionCalls(Connection connection)
        {
            this.connection = connection;
        }

        #region IDataLayerSecurityActionCalls Members

        /// <summary>
        /// Authenticates the specified sercurity principal.
        /// </summary>
        /// <param name="error">The error.</param>
        /// <param name="principal">The security principal.</param>
        /// <returns></returns>
        public SecurityAction Authenticate(out Exception error, ref ISecurityPrincipal principal)
        {
            error = null;

            ////
            //// SAMPLE: We deny authentication if credential is present in %TEMP%\DLSampleDeny.txt
            ////
            //string denyFile = Environment.ExpandEnvironmentVariables(@"%TEMP%\DLSampleDeny.txt");
            //if (ConnectionSecure.AuthenticationToken != null &&
            //    ConnectionSecure.AuthenticationToken.Identity != null &&
            //    File.Exists(denyFile))
            //{
            //    string[] badCreds = File.ReadAllLines(denyFile);
            //    string myCred = ConnectionSecure.AuthenticationToken.Identity.Name;

            //    foreach (string cred in badCreds)
            //    {
            //        if (cred.Equals(myCred, StringComparison.InvariantCultureIgnoreCase))
            //        {
            //            // Found credential. Block access!
            //            error = new System.Security.SecurityException(string.Format("User '{0}' found in deny file", myCred));
            //            return SecurityAction.Deny;
            //        }
            //    }
            //}

            return SecurityAction.Allow;
        }

        #endregion
    }
}
